﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MCMesServer
{
    static class Program
    {
        private static readonly log4net.ILog log_info = log4net.LogManager.GetLogger("loggerinfo");
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            try
            {
                bool createNew;
                using (Mutex mutex = new Mutex(true, Application.ProductName, out createNew))
                {
                    if (createNew)
                    {
                        Application.EnableVisualStyles();
                        Application.SetCompatibleTextRenderingDefault(false);
                        try
                        {
                            log_info.Info("[系统启动]");
                            Application.Run(new MainWindow());
                        }
                        catch (Exception ex)
                        {
                            log_info.Error("打开错误：" + ex.ToString());
                        }
                    }
                    else
                    {
                        MessageBox.Show("应用程序已经在运行中...");
                        Thread.Sleep(1000);
                        log_info.Error("服务器程序已在运行中！");
                        Environment.Exit(1);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
    }
}
